<?php
class User extends Zend_Db_Table{
    	protected $_name ="user";
	protected $_primary = 'user_id';

       // 查询所有user
    public function getAllUsers($page,$perpage,$search_name){
          $where = "1=1";
          if($search_name!=""){
              $where.=" and name like '%$search_name%'";
          }
          $select = $this->select();
          $select->where($where);
          if($page!=""){
          $select->limitPage($page,$perpage);
          }
          $select->order('user_id desc');
          return $this->fetchAll($select)->toArray();
    }
    
    public function getAllUsersexcel(){
          $where = "1=1";
          $select = $this->select();
          $select->where($where);
          if($page!=""){
          $select->limitPage($page,$perpage);
          }
          $select->order('user_id asc');
          return $this->fetchAll($select)->toArray();
    }

  //根据username和password 查询user
    public function getuserByusernameAndpassword($username,$password){
          $select = $this->select();
          $select->where("user_name='".$username."' and password = '$password'");
          return $this->fetchAll($select)->toArray();
    }
    
     //根据user_id 查询user
    public function getuserByuser_id($user_id){
          $select = $this->select();
          $select->where("user_id='".$user_id."'");
          return $this->fetchAll($select)->toArray();
    }
   //根据username 查询user
    public function getuserByusername($username){
          $select = $this->select();
          $select->where("user_name='".$username."'");

          return $this->fetchAll($select)->toArray();
    }
 //更新user
    public function updateuserByuser_id($array,$user_id){

		$db = $this->getAdapter();
		$where=$db->quoteInto('user_id = ?', $user_id);
		$this->update($array, $where);
                return true;
	}
//删除user
     public function deluserByuser_id($user_id){
         $where = 'user_id = '. $user_id;
         $this->delete($where);
         return true;
    }
}
?>
